<template>
  <div>
    <r-search
      :searchForm="searchForm"
      :searchHandle="searchHandle"
      :searchData="searchData"
    />
    <r-table
      :tableHandles="tableHandles"
      :isSelection="false"
      :isIndex="false"
      :isPagination="true"
      :tableData="tableData"
      :tableCols="tableCols"
      :tablePage="tablePage"
      :isHandle="true"
      @refresh="init()"
      @oneClick="oneClick"
    ></r-table>
    <!--    <r-form :formRules="formRules" :formHandle="formHandle" :formData="formData" :formCols="formCols" ref="elForm" labelWidth="200px" dialogWidth="1000px" :isHandle="true" />-->
  </div>
</template>
<script>
export default {
  data() {
    return {
      searchData: {
        deviceType: "1",
        deviceNo: "",
        oprType: "",
        // result: '',
        phone: "",
        orderNo: "",
        batteryNo: "",
        returnBatteryNo: "",
        deviceName: ""
      },
      searchForm: [
        {
          type: "input",
          prop: "deviceNo",
          placeholder: "Device Number",
          width: 240
        },
        {
          type: "input",
          prop: "deviceName",
          placeholder: "Device Name",
          width: 230
        },
        {
          type: "select",
          prop: "oprType",
          placeholder: "Business Type",
          width: 240,
          options: [
            { label: "Keeper Open Door", value: "0" },
            { label: "Rent Battery", value: "1" },
            { label: "Battery Swap", value: "2" },
            { label: "Check Battery", value: "3" },
            { label: "Deposit Return Battery", value: "4" }
          ]
        },
        // {
        //   type: 'select',
        //   prop: 'result',
        //   placeholder: '换电Status',
        //   width: 150,
        //   options: [{ label: 'Failure', value: '0' }, { label: 'Success', value: '1' }]
        // },
        {
          type: "input",
          prop: "phone",
          placeholder: "Phone",
          width: 180
        },
        // {
        //   type: 'input',
        //   prop: 'name',
        //   placeholder: '充取Status',
        //   width: 150
        // },
        {
          type: "input",
          prop: "orderNo",
          placeholder: "Order Nnumber",
          width: 240
        },
        {
          type: "input",
          prop: "batteryNo",
          placeholder: "Collect Battery Number",
          width: 290
        },
        {
          type: "input",
          prop: "returnBatteryNo",
          placeholder: "Return Battery Number",
          width: 290
        }
      ],
      searchHandle: [
        {
          label: "Search",
          type: "success",
          icon: "el-icon-search",
          handle: e => {
            this.zeroFn();
            this.init();
          }
        },
        {
          label: "Reset",
          buttonss: true,
          icon: "el-icon-refresh-right",
          handle: e => {
            this.searchData = {
              deviceType: "1",
              deviceNo: "",
              oprType: "",
              phone: "",
              orderNo: "",
              batteryNo: "",
              returnBatteryNo: ""
            };
            this.zeroFn();
            this.init();
          }
        }
      ],

      tableHandles: [
        // {
        //   label: "ExportData",
        //   type: "primary",
        //   handle: e => this.elFormVisible()
        // }
      ],
      tableData: [],
      tableCols: [
        {
          label: "Device Number",
          prop: "deviceNo"
        },
        {
          label: "Device Name",
          prop: "deviceName"
        },
        {
          label: "User Name",
          prop: "userName"
        },
        {
          label: " User Type",
          prop: "userType",
          formatter: e =>
            e.userType == 1
              ? "WeChat"
              : e.userType == 2
              ? "Alipay"
              : e.userType == 3
              ? "Maintenance"
              : "--"
        },
        // {
        //   label: 'Phone',
        //   prop: 'phone'
        // },
        {
          type: "link",
          label: "Phone",
          prop: "phone",
          width: "120",
          // formatter: e => (e.phone ? e.phone : "--"),
          click: e => {
            if (e.phone) {
              this.$router.push({
                name: "user_management-userOdrer",
                params: { phone: e.phone || "" }
              });
            } else {
              console.log(333, e.phone);
            }
          }
        },
        {
          label: "Collect Battery",
          prop: "cabinetNo",
          formatter: e =>
            e.cabinetNo ? e.cabinetNo + "Number Get Battery" : "--"
        },
        {
          label: "Collect Battery Status",
          prop: "statusStr",
          itemClass: e =>
            e.statusStr == "Number Door Open Failure" ||
            e.statusStr == "Unreceived Battery"
              ? "danger"
              : e.statusStr == "Success"
              ? "success"
              : "",
          formatter: e => (e.statusStr ? e.statusStr : "--")
        },
        {
          label: "Collect Battery",
          prop: "batteryNo",
          formatter: e => (e.batteryNo ? e.batteryNo : "--")
        },
        {
          label: "Return Battery",
          prop: "returnCabinetNo",
          formatter: e =>
            e.returnCabinetNo
              ? e.returnCabinetNo + "Number Door Return Battery"
              : "--"
        },
        {
          label: "Return Battery Status",
          prop: "returnStatusStr",
          itemClass: e =>
            e.returnStatusStr == "Door Open Failure" ||
            e.returnStatusStr == "Not Returned Battery" ||
            e.returnStatusStr == "Illegality Battery" ||
            e.returnStatusStr == "Battery Mismatching"
              ? "danger"
              : e.returnStatusStr == "Success"
              ? "success"
              : "",
          formatter: e => (e.returnStatusStr ? e.returnStatusStr : "--")
        },
        {
          label: "Return Battery",
          prop: "returnBatteryNo",
          formatter: e => (e.returnBatteryNo ? e.returnBatteryNo : "--")
        },
        {
          label: "Business Type",
          prop: "oprType",
          formatter: e =>
            e.oprType == 0
              ? "Keeper Open Door"
              : e.oprType == 1
              ? "Rent Battery"
              : e.oprType == 2
              ? "Battery Swap"
              : e.oprType == 3
              ? "Check Battery"
              : e.oprType == 4
              ? "Deposit Return Battery"
              : "--"
        },

        // {
        //   label: '开门Status',
        //   prop: 'result',
        //   itemClass: e => (e.result == 0 ? 'danger' : e.result == 1 ? 'success' : ''),
        //   formatter: e => (e.result == 0 ? 'Failure' : e.result == 1 ? 'Success' : '--')
        // },
        // {
        //   label: 'BatteryStatus',
        //   prop: 'isBattery',
        //   formatter: e => (e.oprType == 1 && e.isBattery == 0 ? '未领取' : e.oprType == 1 && e.isBattery == 1 ? '已领取' : e.oprType == 2 && e.isReturn == 0 ? 'Not Returned' : e.oprType == 2 && e.isReturn == 1 ? '已Return' : e.oprType == 3 && e.isReturn == 0 ? 'Not Returned' : e.oprType == 3 && e.isReturn == 1 ? '已Return' : e.oprType == 4 && e.isReturn == 0 ? 'Not Returned' : e.oprType == 4 && e.isReturn == 1 ? '已Return' : e.oprType == 0 && e.isBattery == 0 ? '未领取' : e.oprType == 0 && e.isBattery == 1 ? '已领取' : '--'),
        //   itemClass: e => (e.oprType == 2 && e.isReturn == 0 ? 'danger' : e.oprType == 3 && e.isReturn == 0 ? 'danger' : e.oprType == 4 && e.isReturn == 0 ? 'danger' : ''),
        // },
        {
          label: "Order Number",
          prop: "orderNo"
        },
        {
          label: "Operation Time",
          prop: "ctime"
        }
        // { label: "Completion Time", prop: "ftime", },
      ],
      tablePage: { limit: 10, page: 1, total: 0 }
      // formData: {
      //   name: "",
      //   money: "",
      //   giftMoney: "",
      //   status: ""
      // },
      //
      //   { type: "input", label: "Package Name", width: 350, prop: "name" },
      //   { type: "input", label: "PackageMoney", width: 350, prop: "money", remark: '元' },
      //   { type: "input", label: "Gift Amount", width: 350, prop: "giftMoney", remark: '元' },
      //   { type: "switch", label: "上线/下线", width: 350, prop: "status" },
      // ],
      // formRules: {
      //   name: [
      //     { required: true, message: 'Please InputPackage Name', trigger: 'blur' },
      //   ],
      //   money: [
      //     { required: true, message: 'Please InputPackageMoney', trigger: 'blur' },
      //   ],
      //   giftMoney: [
      //     { required: true, message: 'Please InputPackageMoney', trigger: 'blur' },
      //   ],
      // },
      // formHandle: [
      //   {
      //     label: "Cancel",
      //     handle: e => this.elFormVisible(),
      //   },
      //   {
      //     label: "Confirm",
      //     type: "success",
      //     handle: e => this.elFormSubmit(),
      //   },
      //
      // ],
    };
  },
  components: {},
  computed: {},
  mounted() {
    if (this.$route.query.sn) {
      this.searchData.deviceNo = this.$route.query.sn;
    }
    this.init();
  },
  methods: {
    zeroFn() {
      this.tablePage.limit = 10;
      this.tablePage.page = 1;
      this.tablePage.total = 0;
    },
    oneClick(row) {
      // console.log(4576787, row.phone);
    },
    async init() {
      let parm = {
        ...this.searchData,
        ...{
          pageNum: this.tablePage.page,
          pageSize: this.tablePage.limit
        }
      };
      let res = await this.apis.deviceLog_list(parm);
      if (res) {
        this.tableData = res.rows;
        this.tablePage.total = res.total;
      }
    }
    // async elFormSubmit() {
    //   this.formData.state = this.formData.status == true ? 1 : 2
    //   if (this.formData.id) {
    //     let res = await this.api.packupdate(this.formData)
    //     if (res) {
    //       this.formData.id = ''
    //       this.elFormVisible()
    //       this.init()
    //     }
    //   } else {
    //     let res = await this.api.packadd(this.formData)
    //     if (res) {
    //       this.elFormVisible()
    //       this.init()
    //     }
    //   }
    // },
    // async changestate(id) {
    //   let res = await this.api.packchange({ id })
    //   if (res) {
    //     this.init()
    //   }
    // },
    // elFormDetail(row) {
    //   console.log(row);
    //   Object.keys(this.formData).forEach(key => {
    //     this.formData[key] = row[key]
    //   })
    //
    //   this.formData.status=row['state']==1?true:false
    //   this.formData.id = row.id;
    //   // if (this.formCols[1].label == '登录密码') {
    //   //     this.formCols.splice(1, 1)
    //   // }
    //
    //   this.elFormVisible()
    // },
  }
};
</script>
<style scoped lang="scss">
.el-icon-search {
  margin-right: 10px;
}

.Tip {
  margin-left: 20px;
}
</style>
